package com.yanqu.road.dao.impl.activity.toyhouse;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.toyhouse.config.ToyHouseScoreConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ToyHouseScoreConfigDaoImpl extends TempDao {

    private static String getToyHouseScoreConfigSql = "select * from `t_s_activity_toy_house_score` where activityId=?";

    public Map<Integer, ToyHouseScoreConfig> getToyHouseScoreConfigMap(int activityId) {
        Map<Integer, ToyHouseScoreConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getToyHouseScoreConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ToyHouseScoreConfig toyHouseScoreConfig = new ToyHouseScoreConfig();
                toyHouseScoreConfig.setId(rs.getInt("id"));
                toyHouseScoreConfig.setContinuousNum(rs.getInt("continuousNum"));
                toyHouseScoreConfig.setPic(rs.getInt("pic"));
                toyHouseScoreConfig.setScoreAdd(rs.getInt("scoreAdd"));
                map.put(toyHouseScoreConfig.getContinuousNum(), toyHouseScoreConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
